import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:my_meeting/entity/meeting_data.dart';
import 'package:my_meeting/global.dart';
import 'package:my_meeting/utils/log_utils.dart';

class Metting_listLogic extends GetxController {
  var meetingList = <MeetingData>[].obs;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    refreshMeetings();
  }

  void refreshMeetings() {
    meetingList.clear();
    global.getMeetings().then((value) {
      meetingList.assignAll(value);
    });
  }

  String getDisplayTitle(int index) {
    MeetingData data = meetingList[index];
    DateFormat format = DateFormat("yyyy.MM.dd"); // 根据字符串格式设置
    DateTime dateTime = format.parse(data.meetingBeginTime!);

    // 获取今天的日期
    DateTime today = DateTime.now();

    // 判断是否为今天
    bool isToday = dateTime.year == today.year &&
        dateTime.month == today.month &&
        dateTime.day == today.day;

    // 输出结果
    LogD("转换后的日期是: $dateTime");
    LogD("是否是今天: $isToday");
    String formartDate = '${dateTime.month}月/${dateTime.day}日';
    if (isToday) {
      return '今天 | $formartDate';
    } else {
      return formartDate;
    }
  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
    print("会议列表+${global.getMeetings().toString()}");
  }
}
